/*==============================================================================
 * AUTH: Matthew Baum, 9753095
 * DATE: March-03-2012
 * EDIT: March-03-2012
 * DESC: Input validation class that only accepts numbers (integers)
 *==============================================================================*/

package SOEN_Phase_2;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class NumberFieldValidator extends KeyAdapter
{
    // Constructor
    public NumberFieldValidator()
    {
    }

    // Number input validation
    @Override
    public void keyTyped(KeyEvent e)
    {
        // Get the typed character
        char c = e.getKeyChar();

        // Verify it is a valid number, otherwise consume (erase) it
        if
        (
            !((c >= '0') && (c <= '9') ||
            (c == KeyEvent.VK_BACK_SPACE) ||
            (c == KeyEvent.VK_DELETE))
        )
        {
            e.consume();
        }
     }
}
